<?php
namespace Home\Controller;
use Common\Controller\CommonController;

class ApiController extends CommonController {

	/* *
	 * Dragon
	 * 2016-11-27
	 * Api首页
	 * */
	function index() {
		$res = M('Api') -> where($where) -> order('id desc') -> select();
		
		$this -> assign('list', $res);
		
		$this -> display();
	}
	
	/* *
	* Dragon
 	* 2016-11-27
	* 添加
	* */
	function add_api() {
		$model=I('model');
		$name=I('name');
		$param=I('param');
		$ds=I('ds');
		$data=array('model'=>$model,'name'=>$name,'param'=>$param,'ds'=>$ds);
		$res=M('Api')->add($data);
		if ($res) {
			$this -> ajaxReturn(array('s' => true, 'm' => '添加成功'));
		} else {
			$this -> ajaxReturn(array('s' => false, 'm' => '添加失败'));
		}		
	}
	
	
	/* *
	* Dragon
 	* 2016-11-27
	* 修改
	* */
	function api_up() {
		$where['id']=I('id');
		$res=M('Api')->where($where)->find();
		if ($res) {
			$this -> ajaxReturn(array('s' => true, 'd' => $res));
		} else {
			$this -> ajaxReturn(array('s' => false, ));
		}		
	}
	
	
	/* *
	* Dragon
 	* 2016-11-27
	* 修改
	* */
	function up_api() {
		$where['id']=I('id');
		$model=I('model');
		$name=I('name');
		$param=I('param');
		$ds=I('ds');
		$data=array('model'=>$model,'name'=>$name,'param'=>$param,'ds'=>$ds);
		$res=M('Api')->where($where)->save($data);
		if ($res) {
			$this -> ajaxReturn(array('s' => true, 'm' => '修改成功'));
		} else {
			$this -> ajaxReturn(array('s' => false, 'm' => '修改失败'));
		}		
	}
	
	
	
	/* *
	 * Dragon
	 * 2016-11-27
	 * 删除
	 * */
	function del_api() {
		
		$where['id'] = I('id');
		$res = M('Api') -> where($where) -> delete();
		if ($res) {
			$this -> redirect('Api/index');
		}
		
		
	}
	
}
